<%@ page language="java" pageEncoding="UTF-8" %>
<%@ page import="com.alibaba.fastjson.JSONArray" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %>
<%--获取流水号--%>
<%
    Map<String, Object> apidatas = new HashMap<String, Object>();
    BaseBean bb = new BaseBean();
    String formtable = "formtable_main_286";
    String requestid = Util.null2String(request.getParameter("requestid"));
    bb.writeLog(">>>>>getApprovalTest>>>requestid=" + requestid);
    RecordSet rs = new RecordSet();
    try {
        rs.executeQuery("select id,ktszlx,sjmc,kskssj,ksjssj,kssc from "+formtable+" where requestid=?", requestid);
        rs.next();
        String mainid = Util.null2String(rs.getString("id"));
        String ktszlx = Util.null2String(rs.getString("ktszlx"));
        String sjmc = Util.null2String(rs.getString("sjmc"));
        String kskssj = Util.null2String(rs.getString("kskssj"));
        String ksjssj = Util.null2String(rs.getString("ksjssj"));
        String kssc = Util.null2String(rs.getString("kssc"));
        JSONArray dxtlist = new JSONArray();
        JSONArray duoxtlist = new JSONArray();
        JSONArray pdtlist = new JSONArray();
        JSONArray jdtlist = new JSONArray();
        String dxttitle = "";
        String duoxttitle = "";
        String pdttitle = "";
        String jdttitle = "";
        if (ktszlx.contains("0")) {
            bb.writeLog(">>>>>getApprovalTest>>>单选题>>>>");
            rs.executeQuery("select tmwb,fz,tmzf,txnr,tmxxnr from "+formtable+"_dt1 where mainid=? order by px,id", mainid);
            int count = 0;
            int fzs = 0;
            while (rs.next()) {
                JSONObject json = new JSONObject();
                String tmname = Util.null2String(rs.getString("tmwb"));
                String txnr = Util.null2String(rs.getString("txnr"));
                String tmxxnr = Util.null2String(rs.getString("tmxxnr"));
                int fz = Util.getIntValue(rs.getString("fz"));
                fzs = Util.getIntValue(rs.getString("tmzf"));
                json.put("xh", "0_" + count);
                json.put("tm", tmname);
                json.put("fz", fz);
                json.put("child", JSONArray.parseArray(tmxxnr));
                JSONObject dajson = new JSONObject();
                dajson.put("xzdaid", txnr);
                dajson.put("xzdamc", "");
                json.put("da", dajson);
                bb.writeLog(">>>>>getApprovalTest>>>单选题>>>>json="+json);
                dxtlist.add(json);
                count++;
            }
            bb.writeLog(">>>>>getApprovalTest>>>单选题>>>>dxtlist="+dxtlist.toJSONString());
            dxttitle = "共" + count + "题，合计" + fzs + "分";
        }
        if (ktszlx.contains("1")) {
            bb.writeLog(">>>>>getApprovalTest>>>多选题>>>>");
            rs.executeQuery("select tmwb,fz,tmzf,txnr,tmxxnr from "+formtable+"_dt2 where mainid=? order by px,id", mainid);
            int count = 0;
            int fzs = 0;
            while (rs.next()) {
                JSONObject json = new JSONObject();
                String tmname = Util.null2String(rs.getString("tmwb"));
                String txnr = Util.null2String(rs.getString("txnr"));
                String tmxxnr = Util.null2String(rs.getString("tmxxnr"));
                int fz = Util.getIntValue(rs.getString("fz"));
                fzs = Util.getIntValue(rs.getString("tmzf"));
                json.put("xh", "1_" + count);
                json.put("tm", tmname);
                json.put("fz", fz);
                json.put("child", JSONArray.parseArray(tmxxnr));
                JSONObject dajson = new JSONObject();
                dajson.put("xzdaid", txnr);
                dajson.put("xzdamc", "");
                json.put("da", dajson);
                bb.writeLog(">>>>>getApprovalTest>>>多选题>>>>json="+json);
                duoxtlist.add(json);
                count++;
            }
            bb.writeLog(">>>>>getApprovalTest>>>多选题>>>>duoxtlist="+duoxtlist.toJSONString());
            duoxttitle = "共" + count + "题，合计" + fzs + "分";
        }
        if (ktszlx.contains("2")) {
            bb.writeLog(">>>>>getApprovalTest>>>判断题>>>>");
            rs.executeQuery("select tm,tmwb,fz,tmzf,txnr,tmxxnr from "+formtable+"_dt3 where mainid=? order by px,id", mainid);
            int count = 0;
            int fzs = 0;
            while (rs.next()) {
                JSONObject json = new JSONObject();
                String tm = Util.null2String(rs.getString("tm"));
                String tmname = Util.null2String(rs.getString("tmwb"));
                String txnr = Util.null2String(rs.getString("txnr"));
                String tmxxnr = Util.null2String(rs.getString("tmxxnr"));
                int fz = Util.getIntValue(rs.getString("fz"));
                fzs = Util.getIntValue(rs.getString("tmzf"));
                json.put("xh", "2_" + count);
                json.put("tm", tmname);
                json.put("fz", fz);
                json.put("child", JSONArray.parseArray(tmxxnr));
                JSONObject dajson = new JSONObject();
                dajson.put("xzdaid", txnr);
                dajson.put("xzdamc", getPdtxx(tm, txnr));
                json.put("da", dajson);
                bb.writeLog(">>>>>getApprovalTest>>>判断题>>>>json="+json);
                pdtlist.add(json);
                count++;
            }
            bb.writeLog(">>>>>getApprovalTest>>>判断题>>>>pdtlist="+pdtlist.toJSONString());
            pdttitle = "共" + count + "题，合计" + fzs + "分";
        }
        if (ktszlx.contains("3")) {
            bb.writeLog(">>>>>getApprovalTest>>>简答题>>>>");
            rs.executeQuery("select tmwb,fz,tmzf,txnr,tmxxnr,df from "+formtable+"_dt4 where mainid=? order by px,id", mainid);
            int count = 0;
            int fzs = 0;
            while (rs.next()) {
                JSONObject json = new JSONObject();
                String tmname = Util.null2String(rs.getString("tmwb"));
                String txnr = Util.null2String(rs.getString("txnr"));
                String tmxxnr = Util.null2String(rs.getString("tmxxnr"));
                int fz = Util.getIntValue(rs.getString("fz"));
                String df = Util.null2String(rs.getString("df"));
                fzs = Util.getIntValue(rs.getString("tmzf"));
                json.put("xh", "3_" + count);
                json.put("tm", tmname);
                json.put("fz", fz);
                json.put("child", JSONArray.parseArray(tmxxnr));
                JSONObject dajson = new JSONObject();
                dajson.put("xzdaid", "1");
                dajson.put("xzdamc", txnr);
                dajson.put("df", df);
                json.put("da", dajson);
                bb.writeLog(">>>>>getApprovalTest>>>简答题>>>>json="+json);
                jdtlist.add(json);
                count++;
            }
            bb.writeLog(">>>>>getApprovalTest>>>简答题>>>>jdtlist="+jdtlist.toJSONString());
            jdttitle = "共" + count + "题，合计" + fzs + "分";
        }
        apidatas.put("examtime", kssc);
        apidatas.put("examname", sjmc);
        apidatas.put("exambegdate", kskssj);
        apidatas.put("examenddate", ksjssj);
        apidatas.put("dxttitle", dxttitle);
        apidatas.put("duoxttitle", duoxttitle);
        apidatas.put("pdttitle", pdttitle);
        apidatas.put("jdttitle", jdttitle);
        apidatas.put("dxt", dxtlist);
        apidatas.put("duoxt", duoxtlist);
        apidatas.put("pdt", pdtlist);
        apidatas.put("jdt", jdtlist);
        bb.writeLog(">>>>>getApprovalTest>>>apidatas=" + apidatas.toString());
    } catch (Exception e) {
        e.printStackTrace();
        apidatas.put("api_status", false);
    }
    out.print(JSONObject.toJSONString(apidatas));
%>
<%!

    /**
     * 转换考试选项
     */
    public String getPdtxx(String id,String xh) {
        RecordSet rs = new RecordSet();
        rs.executeQuery("select id from uf_ktsz where id=?", id);
        rs.next();
        String mainid = Util.null2String(rs.getString("id"));
        rs.executeQuery("select xx from uf_ktsz_dt1 where mainid=? and px=?", mainid,xh);
        rs.next();
        return Util.null2String(rs.getString(1));
    }

%>



